#pragma once
#include "aes.h"

#ifdef __cplusplus  
extern "C" {  
#endif

struct p_module_unit
{
    char filename[256];
    char note[128];
    char publisher[64];
    char version[32];
    char pla_sign[32];
    char cip_sign[32];
    char *data;
    int data_len;
    char type;
    struct p_module_unit *next;
};

struct package_frame
{
    AESInfo_t ainfo;
    char isEncrypt;
    struct p_module_unit *unit;
    void *head;
};

/* usual */
/**
 * @param ukey is a 32 bytes secret key
 * @return int 0 for success
 */
int package_frame_init(struct package_frame *pak, char *ukey, char is_encrypt);
void package_frame_free(struct package_frame *pak);

/* create */
/**
 * @param type user define
 * @return int 0 for success
 * @note all params need to pass value, null is not allow
 */
int package_frame_append(struct package_frame *pak, 
                         const char *filename,
                         const char *publisher,
                         const char *note,
                         const char *version,
                         char type);
/**
 * @brief package all append into one file
 */
int package_frame_generate(struct package_frame *pak, char *filename);

/* extract */ 
/**
 * @brief analysis package
 * @return how many files it can analysis
 */
int package_frame_read_package(struct package_frame *pak, char *filename);
/**
 * @brief 
 * @param filename select which file should be output
 * @param dest_path output file to which path
 * @return return file number that be output
 */
int package_frame_output_file(struct package_frame *pak, char *filename, char *dest_path);
int package_frame_output_all(struct package_frame *pak, char *dest_path);

/* else */
void merge_file(char *file1, char *file2, char *outfile);
const char *package_frame_version(void);

#ifdef __cplusplus  
}  
#endif // __cplusplus 
